package cn.ecut.reflection;

import java.lang.reflect.Field;

/**
 * @Author ruanxin
 */

//反射机制
public class Test02 {

    public static void main(String[] args) throws ClassNotFoundException {
        //通过反射机制获取类对象
        Class c1 = Class.forName("cn.ecut.reflection.User");
        System.out.println(c1);
        Class c2 = Class.forName("cn.ecut.reflection.User");
        Class c3 = Class.forName("cn.ecut.reflection.User");
        Class c4 = Class.forName("cn.ecut.reflection.User");
        Class c5 = Class.forName("cn.ecut.reflection.User");

        //一个类在内存中只有一个Class对象
        //一个类被加载后，类的整个结构都会被封装到Class对象中
        System.out.println(c1.hashCode());
        System.out.println(c2.hashCode());
        System.out.println(c3.hashCode());
        System.out.println(c4.hashCode());
        System.out.println(c5.hashCode());
    }


}

//实体类:pojo entity
class User {
    private String name;
    public int id;
    public int age;
    private int sb;
    protected String bir;
    double money;

    private void testmethod(){
        System.out.println("一个默认的私有方法");
    }

    @Override
    public String toString() {
        return "User{" +
                "name='" + name + '\'' +
                ", id=" + id +
                ", age=" + age +
                ", sb=" + sb +
                ", bir='" + bir + '\'' +
                ", money=" + money +
                '}';
    }

    public User() {
    }

    public User(String name, int id, int age, int sb, String bir, double money) {
        this.name = name;
        this.id = id;
        this.age = age;
        this.sb = sb;
        this.bir = bir;
        this.money = money;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public int getSb() {
        return sb;
    }

    public void setSb(int sb) {
        this.sb = sb;
    }

    public String getBir() {
        return bir;
    }

    public void setBir(String bir) {
        this.bir = bir;
    }

    public double getMoney() {
        return money;
    }

    public void setMoney(double money) {
        this.money = money;
    }
}
